package main.java.indi.zyj.c150.recursion;

public class _03_BinarySearch {


    public static void main(String[] args) {
        int[] arr = new int[]{1, 3, 2, 5};
        System.out.println(BinarySearchRecursion(arr, 0, 3, 3));
    }


    static int BinarySearchRecursion(int[] arr, int low, int high, int target){
        if (low > high){
            return -1;
        }
        int mid = (low + high) / 2;
        int val = arr[mid];
        if (val == target){
            return mid;
        }else if (val > target){
            return BinarySearchRecursion(arr, low, mid - 1, target);
        }else {
            return BinarySearchRecursion(arr, mid + 1, high, target);
        }

    }

}
